/**
 * 删除上传的图片
 */
function deleteCover(value) {
    $("#" + value).remove();
}

/**
 * 会员
 */

define([
    'jquery',
    'baseUtils',
    'base',
    'msgTool',
    'css!global/plugins/wangEditor/wangEditor.min.css',
    'plugins/wangEditor/wangEditor.min',
    'css!global/plugins/fileInput/fileinput.min.css',
    'plugins/fileInput/fileinput.min',
    'plugins/bootstrap-table/bootstrap-table',
    "plugins/bootstrap-dialog/bootstrap-dialog",
    "css!global/plugins/bootstrap-dialog/bootstrap-dialog.css",
    'iCheck',
    'css!global/plugins/iCheck/icheck.min.css'
], function ($, baseUtils, base, msgTool, _, E, _, _, _, BootstrapDialog,iCheck) {
    //默认加载基础库
    base();
    //执行
    return {
        info: function () { 
        	$("input[name='sex']").iCheck({
				checkboxClass: 'icheckbox_square-green',
				radioClass: 'iradio_square-green',
				increaseArea: '10%' // optional
			});
            //健康证照片
            oneUploader("#healthCertPictureUploader", "请选择健康证照片" , "#healthCertPicture-upload-error", "#healthCertPicture-upload-success", "healthCertPicture");
            
            
            function oneUploader(node, placeholder, elErrorContainer, successContainer, name) {
                return $(node).fileinput({
                    //设置语言
                    language: 'zh',
                    //上传的地址
                    uploadUrl: '/common/uploader/index',
                    //上传方式
                    method: 'post',
                    //文件筐信息
                    msgPlaceholder: placeholder,
                    //附加属性(0图片，1文件)
                    uploadExtraData: {filesType: 0},
                    //上传类型
                    allowedFileExtensions: ['jpg', 'gif', 'png', 'jpeg'],
                    //是否显示图片展示框
                    showPreview: false,
                    //是否显示上传按钮
                    showUpload: true,
                    //是否显示取消按钮
                    showCancel: false,
                    //是否显示上传输入框
                    showCaption: true,
                    //是否显示删除键
                    showRemove: false,
                    //浏览图标
                    browseIcon: '<i class="iconfont icon-wenjianjia"></i>&nbsp;',
                    //浏览样式
                    browseClass: 'btn btn-success btn-outline',
                    //上传图标
                    uploadIcon: '<i class="iconfont icon-upload"></i>&nbsp;',
                    //上传样式
                    uploadClass: 'btn btn-success btn-outline',
                    //单位为kb，(30M)如果为0表示不限制文件大小
                    maxFileSize: 10720,
                    //错误显示位置
                    elErrorContainer: elErrorContainer,
                    //错误显示位置节点样式
                    msgErrorClass: 'alert alert-block alert-danger',
                    //验证数量
                    validateInitialCount: true
                }).on("fileuploaded", function (event, data) {
                    if (data.response !== null && data.response.status) {
                        $(successContainer).html("<div  id=\"" + data.response.nodeId + "\"><div class=\"thumbnail uploadImageShow\"><input type=\"hidden\" name=\"" + name + "\" value=\"" + data.response.url + "\"><a href=\"" + data.response.domain + data.response.url + "\" target='_blank'><img src=\"" + data.response.domain + data.response.url + "\"></a><div class=\"btn btn-block btn-danger deletetCover\" onclick=\"deleteCover('" + data.response.nodeId + "')\">删除</div></div>");
                    } else {
                        $(elErrorContainer).text(data.response.message);
                    }
                });
            }
            

            /**
             * 提交食药从业人员申请
             */

            $("#submitEmployee").on('click', function () {
            	 var reg_phone = /^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8]))\d{8}$/;//验证手机号
        		 var reg_IDcard = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/; //验证身份证号
        		 var name = $("#name").val();
           	     var nation=$("#nation").val();
           	     var householdAddress=$("#householdAddress").val();
              	 var cardType= $("#cardType").val();
              	 var cardNumber= $("#cardNumber").val();
              	 var phone= $("#phone").val();
              	 var healthCertNumber=$("#healthCertNumber").val();
              	 var healthCertLeader=$("#healthCertLeader").val();
              	 var healthCertPicture= $("input[name='healthCertPicture']").val();
               if(name==''){
              	$("#name-error").html("(姓名不能为空)");
              	return false;
               }else{
            	$("#name-error").html("");  
               }
               if(nation==''){
           	   $("#nation-error").html("(民族不能为空)");
           	   return false;
               }else{
               $("#nation-error").html("");  
               }
               if(householdAddress==''){
                $("#householdAddress-error").html("(户籍地址不能为空)");
                return false;
               }else{
            	$("#householdAddress-error").html("");  
               }
               if(cardType==''){
              	 $("#cardType-error").html("(证件类型不能为空)");
              	return false;
               }
               if(cardNumber==''){
              	 $("#cardNumber-error").html("(证件号码不能为空)"); 
              	return false;
               }else{
            	   if(cardType==1){
               		if (!reg_IDcard.test(cardNumber)){
                    		  $("#cardNumber-error").html("请输入正确的证件号码");
           					return false;
           				}else{
           				  $("#cardNumber-error").html("");	
           				}	
               	}else{
               		 $("#cardNumber-error").html("");	
               	}
               }
               if(phone==''){
              	 $("#phone-error").html("(手机号不能为空)"); 
              	return false;
               }else{
            	   if (!reg_phone.test(phone)){
             		  $("#phone-error").html("(请输入正确的手机号码)");
    					return false;
    				}else{
    				  $("#phone-error").html("");	
    				}
               }
               if(healthCertNumber==''){
            	  $("#healthCertNumber-error").html("(健康证编号不能为空)"); 
            	  return false;
               }else{
       				 $("#healthCertNumber-error").html(""); 
               }
               if(healthCertLeader==''){
            	 $("#healthCertLeader-error").html("(发证单位不能为空)"); 
            	 return false;
               }else{
            	   $("#healthCertLeader-error").html("");  
               }
               if(healthCertPicture==undefined){
              	 $("#healthCertPicture-error").html("(健康证照不能为空)"); 
              	 return false;
               }else{
            	   $("#healthCertPicture-error").html(""); 
               }
               $("#saveEmployeeForm").submit();
              });
            
            $("#cancelEmployee").on('click', function () {
            	var applyId=$("#applyId").val();
            	var changeId=$("#changeId").val();
            	if(changeId==undefined){
            		window.location.href="/fooddrugApply/employeeList?applyId="+applyId;
            	}
            	if(applyId==undefined){
            		window.location.href="/fooddrugChange/employeeList?changeId="+changeId;
            	}
            });
           
          
        },

    	 /**
         * 列表
         */
        list: function () {

            var myTable = $('#employeeList');
            var tableRefresh = function () {
                myTable.bootstrapTable('refresh', {url: 'member/api.json'})
            };

            //table当前行的响应事件
            window.operateEvents = {
                'click.update': function (e, value, row) {
                    winModal("编辑", row);
                },
                'click.delete': function (e, value, row) {
                    $.baseUtils.oneDelete({
                        row: row,
                        tableName: myTable,
                        nameText: '姓名',
                        nameValue: row.name,
                        url: '/fooddrug/deleteEmployee/action'
                    });
                }
            };

            //table表格
            myTable.bootstrapTable({
                url: 'member/api.json', // 接口 URL 地址
                cache: false, // 不缓存
                striped: true, // 隔行加亮
                pagination: true, // 开启分页功能
                sidePagination: 'server',//服务端分页
                sortOrder: 'desc', // 设置排序为反序 desc
                fixedColumns: true,//自动修复
                queryParams: queryParams,//搜索附加参数
                smartDisplay: false, // 智能显示 pagination 和 cardview 等
                toolbar: ".toolBar", //顶部工具菜单
                toolbarAlign: "right", //顶部工具位置
                mobileResponsive: "true", //手机模式自适应宽度（自动变成卡片模式）
                columns: [
                    {
                        field: 'rowno',
                        title: '序号',
                        formatter: function (value, row, index) {  
                            return index+1;  
                        },  
                        align:'center'
                    }, {
                        field: 'name',
                        title: '姓名',
                        align: 'center'
                    }, {
                        field: 'sex',
                        title: '性别',
                        formatter: function (value) {
                        	  var result = null;
                              switch (value) {
                                  case 1:
                                      result = "男";
                                      break;
                                  case 2:
                                      result = "女";
                                      break;
                                  default:
                                      result = "未知";
                                      break;
                              }
                              return result;
                        }
                    }, {
                        field: 'nation',
                        title: '民族',
                        formatter: function (value) {
                        	var result = null;
                        	switch(value)
                        	{
                        	case  1:result="汉族";  break;
                        	case  2:result="阿昌族";  break;
                        	case  3:result="白族";  break;
                        	case  4:result="保安族";  break;
                        	case  5:result="布朗族";  break;
                        	case  6:result="布依族";  break;
                        	case  7:result="朝鲜族";  break;
                        	case  8:result="达斡尔族";  break;
                        	case  9:result="傣族";  break;
                        	case  10:result="德昂族";  break;
                        	case  11:result="侗族";  break;
                        	case  12:result="东乡族";  break;
                        	case  13:result="独龙族";  break;
                        	case  14:result="鄂伦春族";  break;
                        	case  15:result="俄罗斯族";  break;
                        	case  16:result="鄂温克族";  break;
                        	case  17:result="高山族";  break;
                        	case  18:result="仡佬族";  break;
                        	case  19:result="哈尼族";  break;
                        	case  20:result="哈萨克族";  break;
                        	case  21:result="赫哲族";  break;
                        	case  22:result="回族";  break;
                        	case  23:result="基诺族";  break;
                        	case  24:result="京族";  break;
                        	case  25:result="景颇族";  break;
                        	case  26:result="柯尔克孜族";  break;
                        	case  27:result="拉祜族";  break;
                        	case  28:result="黎族";  break;
                        	case  29:result="傈僳族";  break;
                        	case  30:result="珞巴族";  break;
                        	case  31:result="满族";  break;
                        	case  32:result="毛南族";  break;
                        	case  33:result="门巴族";  break;
                        	case  34:result="蒙古族";  break;
                        	case  35:result="苗族";  break;
                        	case  36:result="仫佬族";  break;
                        	case  37:result="纳西族";  break;
                        	case  38:result="怒族";  break;
                        	case  39:result="普米族";  break;
                        	case  40:result="羌族";  break;
                        	case  41:result="撒拉族";  break;
                        	case  42:result="畲族";  break;
                        	case  43:result="水族";  break;
                        	case  44:result="塔吉克族";  break;
                        	case  45:result="塔塔尔族";  break;
                        	case  46:result="土族";  break;
                        	case  47:result="土家族";  break;
                        	case  48:result="佤族";  break;
                        	case  49:result="维吾尔族";  break;
                        	case  50:result="乌兹别克族";  break;
                        	case  51:result="锡伯族";  break;
                        	case  52:result="瑶族";  break;
                        	case  53:result="彝族";  break;
                        	case  54:result="裕固族";  break;
                        	case  55:result="藏族";  break;
                        	case  56:result="壮族";  break;
                        	default:
                        	  result=="未知";  break;
                        	}
                        	 return result;
                        }
                    },
                    {
                        field: 'job',
                        title: '职务',
                        formatter: function (value) {
                            var result = null;
                            switch (value) {
                                case 1:
                                    result = "食品安全技术人员";
                                    break;
                                case 2:
                                    result = "食品安全管理人员";
                                    break;
                                case 3:
                                    result = "其他人员";
                                    break;
                                default:
                                    result = "未知";
                                    break;
                            }
                            return result;
                        }
                    }, {
                        field: 'cardNumber',
                        title: '身份证号码',
                        align: 'center'
                    }, {
                        field: 'phone',
                        title: '手机号码',
                        align: 'center'
                    }, {
                        field: 'healthCertNumber',
                        title: '健康证编号',
                        align: 'center'
                    }, {
                        field: 'action',
                        title: '操作',
                        align: 'center',
                        formatter: operateFormatter,
                        events: operateEvents
                    }
                ]
            });
            //查询条件  
            function queryParams(params) {  
            	var applyId=$("#applyId").val();
            	var changeId=$("#changeId").val();
            	if(changeId==undefined){
            		return {  
            			role:'3',
            			applyId:applyId
            		};  
            	}
            	if(applyId==undefined){
            		return {  
            			role:'3',
            			changeId:changeId
            		};  
            	}
            }  

        },

        /**
         * 查看
         */
        view: function () {

        }
    }
});


